extends Control

var hearts = 4 setget set_hearts
var max_hearts = 4 setget set_max_hearts

onready var heartUIFull = $HeartUIFull
onready var heartUIEmpty = $HeartUIEmpry

func set_hearts(val):
	hearts = clamp(val,0,max_hearts)
	if heartUIFull:
		heartUIFull.rect_size.x = hearts * 15 
		
func set_max_hearts(val):
	max_hearts = max(val , 1)
	self.hearts = min(hearts,max_hearts)
	if heartUIEmpty:
		heartUIEmpty.rect_size.x = max_hearts * 15
		
func _ready():
	self.max_hearts = PlayStats.max_health
	self.hearts = PlayStats.health
	PlayStats.connect("health_change",self,"set_hearts")
	PlayStats.connect("max_health_change",self,"set_max_hearts")
